<template>
    <div v-show="showConfirm">
        <div id="com_black" class="js_com_black hide_com_buy com_black" @click="closeConfirmView"></div>
        <div class="js_hide_com js_delAddress_alert comafter delete-address-alert flex-row">
            <div class="delete-address-alert-info">
                <div class="delete-address-alert-msg" v-html="msg"></div>
                <div class="flex-row">
                    <div class="flex-data delete-address-alert-btn delete-address-alert-cancel"
                         @click="closeConfirmView">{{cancel}}
                    </div>
                    <div class="flex-data delete-address-alert-btn delete-address-alert-sure js_delAddress_sure"
                        @click="confirmSure">{{sure}}</div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import xurl from '../../../x/xurl'
    export default {
        data(){
            return{
                showConfirm:false,
                msg:'确定要删除该收货地址？',
                cancel:'取消',
                sure:'确定',
                url:'',
                type:0
            }
        },
        methods:{
            showConfirmView(msg,url,type,cancel){
                this.msg = msg;
                this.url = url;
                this.type = type;
                if (cancel){
                    this.cancel = cancel
                }
                this.showConfirm = true;
            },
            closeConfirmView(){
                this.msg = '';
                this.url = '';
                this.type = 0;
                this.showConfirm = false;
            },
            confirmSure(){
                if (this.type == 0) {
                    xurl.get(this.url).then((data) => {
                        if (data.success) {
                            this.$emit('confirmSure','true')
                        }else{
                            this.$emit('confirmSure',data.errMsg)
                        }
                    })
                }else if (this.type == 1) {
                    xurl.post(this.url).then((data) => {
                        if (data.success) {
                            this.$emit('confirmSure','true')
                        }else{
                            this.$emit('confirmSure',data.errMsg)
                        }
                    })
                }else if (this.type == 2){
                    xurl.put(this.url).then((data) => {
                        if (data.success) {
                            this.$emit('confirmSure','true')
                        }else{
                            this.$emit('confirmSure',data.errMsg)
                        }
                    })
                }
                this.closeConfirmView()
            }
        }
    }
</script>

<style lang="scss" scoped>
    @import url($css_root + 'css/app_downAlert.css');
    @import url($css_root + 'css/retailCommon.css');
    @import url($css_root + 'css/retail-addAddress.css');
    @import url($css_root + 'css/retail-refundSubmit.css');
</style>
